#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
class Solution
{
public:
    vector<string> uncommonFromSentences(string s1, string s2)
    {
        vector<string> ans;
        auto stringToMap = [](string inStr) -> unordered_map<string, int>
        {
            unordered_map<string, int> inStrMap;
            inStr.append(" ");
            int sLen = inStr.length();
            string temStr = "";
            for (int i = 0; i < sLen; i++)
            {
                if (' ' == inStr[i])
                {
                    inStrMap[temStr]++;
                    temStr = "";
                }
                else
                {
                    temStr.push_back(inStr[i]);
                }
            }
            return inStrMap;
        };
        unordered_map<string, int> s1Map = stringToMap(s1);
        unordered_map<string, int> s2Map = stringToMap(s2);
        for (auto &s : s1Map)
        {
            if (1 == s.second && s2Map.find(s.first) == s2Map.end())
            {
                ans.push_back(s.first);
            }
        }
        for (auto &s : s2Map)
        {
            if (1 == s.second && s1Map.find(s.first) == s1Map.end())
            {
                ans.push_back(s.first);
            }
        }
        return ans;
    }

    vector<string> uncommonFromSentences_2(string s1, string s2)
    {
        vector<string> ans;
        unordered_map<string, int> strMap;
        s1.append(" ").append(s2).append(" ");
        int sLen = s1.length();
        string temStr = "";
        for (int i = 0; i < sLen; i++)
        {
            if (' ' == s1[i])
            {
                strMap[temStr]++;
                temStr = "";
            }
            else
            {
                temStr.push_back(s1[i]);
            }
        }
        for (auto &s : strMap)
        {
            if (1 == s.second)
            {
                ans.push_back(s.first);
            }
        }
        return ans;
    }
};
int main()
{
    Solution s;
    string s1 = "d b zu d t", s2 = "udb zu ap";
    vector<string> ans = s.uncommonFromSentences(s1, s2);
    for (string a : ans)
    {
        cout << a << " ";
    }
    cout << endl;
    return 0;
}